import sys
from pathlib import Path
import json

rnoh_folder = sys.argv[1]
package_path = sys.argv[2]

rn_npm_path = list((Path(rnoh_folder) / "react-native-harmony").glob("rnoh-react-native-harmony-*.tgz"))
assert len(rn_npm_path) == 1, f"Found {len(rn_npm_path)} rnoh-react-native-harmony-*.tgz"
rn_npm_path = rn_npm_path[0]

rn_cli_path = list((Path(rnoh_folder) / "react-native-harmony-cli").glob("rnoh-react-native-harmony-cli-*.tgz"))
assert len(rn_cli_path) == 1, f"Found {len(rn_cli_path)} rnoh-react-native-harmony-cli-*.tgz"
rn_cli_path = rn_cli_path[0]

package_json = json.load(open(package_path, "r"))
package_json["dependencies"]["react-native-harmony"] = f"file:{rn_npm_path}"
package_json["dependencies"]["react-native-harmony-cli"] = f"file:{rn_cli_path}"
json.dump(package_json, open(package_path, "w"), indent=2)

"""
python set_dep_version.py /home/user/Desktop/git/perf/ohos_react_native /home/user/Desktop/git/perf/rnoh_benchmark/package.json
"""
